home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet multimedia / Muzyka / Edytory sampli (probek dzwieku) / ZynAddSubFX_2.2.0 / Setup_ZynAddSubFX-2.2.0.exe / source code / Params / EnvelopeParams.C < prev    next >
C/C++ Source or Header  |  2005-03-14  |  6KB  |  228 lines

  1. /*
  2.   ZynAddSubFX - a software synthesizer
  3.  
  4.   EnvelopeParams.C - Parameters for Envelope
  5.   Copyright (C) 2002-2005 Nasca Octavian Paul
  6.   Author: Nasca Octavian Paul
  7.  
  8.   This program is free software; you can redistribute it and/or modify
  9.   it under the terms of version 2 of the GNU General Public License 
  10.   as published by the Free Software Foundation.
  11.  
  12.   This program is distributed in the hope that it will be useful,
  13.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.   GNU General Public License (version 2) for more details.
  16.  
  17.   You should have received a copy of the GNU General Public License (version 2)
  18.   along with this program; if not, write to the Free Software Foundation,
  19.   Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  20.  
  21. */
  22.  
  23. #include <stdio.h>
  24.  
  25. #include <math.h>
  26. #include <stdlib.h>
  27. #include "EnvelopeParams.h"
  28.  
  29. EnvelopeParams::EnvelopeParams(unsigned char Penvstretch_,unsigned char Pforcedrelease_):Presets(){
  30.     int i;
  31.     
  32.     PA_dt=10;PD_dt=10;PR_dt=10;PA_val=64;PD_val=64;PS_val=64;PR_val=64;
  33.     
  34.     for (i=0;i<MAX_ENVELOPE_POINTS;i++){
  35.     Penvdt[i]=32;
  36.     Penvval[i]=64;
  37.     };
  38.     Penvdt[0]=0;//no used
  39.     Penvsustain=1;
  40.     Penvpoints=1;
  41.     Envmode=1;
  42.     Penvstretch=Penvstretch_;
  43.     Pforcedrelease=Pforcedrelease_;        
  44.     Pfreemode=1;
  45.     Plinearenvelope=0;
  46.     
  47.     store2defaults();
  48. };
  49.  
  50. EnvelopeParams::~EnvelopeParams(){
  51. };
  52.  
  53. REALTYPE EnvelopeParams::getdt(char i){
  54.     REALTYPE result=(pow(2.0,Penvdt[i]/127.0*12.0)-1.0)*10.0;//miliseconds
  55.     return(result);
  56. };
  57.  
  58.  
  59. /*
  60.  * ADSR/ASR... initialisations
  61.  */
  62. void EnvelopeParams::ADSRinit(char A_dt,char D_dt,char S_val,char R_dt){
  63.     setpresettype("Penvamplitude");
  64.     Envmode=1;
  65.     PA_dt=A_dt;PD_dt=D_dt;PS_val=S_val;PR_dt=R_dt;
  66.     Pfreemode=0;
  67.     converttofree();
  68.  
  69.     store2defaults();
  70. };
  71.  
  72. void EnvelopeParams::ADSRinit_dB(char A_dt,char D_dt,char S_val,char R_dt){
  73.     setpresettype("Penvamplitude");
  74.     Envmode=2;
  75.     PA_dt=A_dt;PD_dt=D_dt;PS_val=S_val;PR_dt=R_dt;
  76.     Pfreemode=0;
  77.     converttofree();
  78.  
  79.     store2defaults();
  80. };
  81.  
  82. void EnvelopeParams::ASRinit(char A_val,char A_dt,char R_val,char R_dt){
  83.     setpresettype("Penvfrequency");
  84.     Envmode=3;
  85.     PA_val=A_val;PA_dt=A_dt;PR_val=R_val;PR_dt=R_dt;
  86.     Pfreemode=0;
  87.     converttofree();
  88.  
  89.     store2defaults();
  90. };
  91.  
  92. void EnvelopeParams::ADSRinit_filter(char A_val,char A_dt,char D_val,char D_dt,char R_dt,char R_val){
  93.     setpresettype("Penvfilter");
  94.     Envmode=4;
  95.     PA_val=A_val;PA_dt=A_dt;PD_val=D_val;PD_dt=D_dt;PR_dt=R_dt;PR_val=R_val;
  96.     Pfreemode=0;
  97.     converttofree();
  98.     store2defaults();
  99. };
  100.  
  101. void EnvelopeParams::ASRinit_bw(char A_val,char A_dt,char R_val,char R_dt){
  102.     setpresettype("Penvbandwidth");
  103.     Envmode=5;
  104.     PA_val=A_val;PA_dt=A_dt;PR_val=R_val;PR_dt=R_dt;
  105.     Pfreemode=0;
  106.     converttofree();
  107.     store2defaults();
  108. };
  109.  
  110. /*
  111.  * Convert the Envelope to freemode
  112.  */
  113. void EnvelopeParams::converttofree(){
  114.     switch (Envmode){
  115.     case 1:    Penvpoints=4;Penvsustain=2;
  116.         Penvval[0]=0;Penvdt[1]=PA_dt;Penvval[1]=127;
  117.         Penvdt[2]=PD_dt;Penvval[2]=PS_val;
  118.         Penvdt[3]=PR_dt;Penvval[3]=0;    
  119.         break;
  120.     case 2: Penvpoints=4;Penvsustain=2;
  121.         Penvval[0]=0;Penvdt[1]=PA_dt;
  122.         Penvval[1]=127;Penvdt[2]=PD_dt;
  123.         Penvval[2]=PS_val;Penvdt[3]=PR_dt;Penvval[3]=0;    
  124.         break;    
  125.     case 3:    Penvpoints=3;Penvsustain=1;
  126.             Penvval[0]=PA_val;Penvdt[1]=PA_dt;
  127.         Penvval[1]=64;Penvdt[2]=PR_dt;Penvval[2]=PR_val;
  128.         break;
  129.     case 4:    Penvpoints=4;Penvsustain=2;
  130.         Penvval[0]=PA_val;Penvdt[1]=PA_dt;
  131.         Penvval[1]=PD_val;Penvdt[2]=PD_dt;Penvval[2]=64;
  132.         Penvdt[3]=PR_dt;Penvval[3]=PR_val;
  133.         break;
  134.     case 5:    Penvpoints=3;Penvsustain=1;
  135.             Penvval[0]=PA_val;Penvdt[1]=PA_dt;
  136.         Penvval[1]=64;Penvdt[2]=PR_dt;Penvval[2]=PR_val;
  137.         break;
  138.     };
  139. };
  140.  
  141.  
  142.  
  143.  
  144. void EnvelopeParams::add2XML(XMLwrapper *xml){
  145.     xml->addparbool("free_mode",Pfreemode);    
  146.     xml->addpar("env_points",Penvpoints);
  147.     xml->addpar("env_sustain",Penvsustain);
  148.     xml->addpar("env_stretch",Penvstretch);
  149.     xml->addparbool("forced_release",Pforcedrelease);
  150.     xml->addparbool("linear_envelope",Plinearenvelope);
  151.     xml->addpar("A_dt",PA_dt);
  152.     xml->addpar("D_dt",PD_dt);
  153.     xml->addpar("R_dt",PR_dt);
  154.     xml->addpar("A_val",PA_val);
  155.     xml->addpar("D_val",PD_val);
  156.     xml->addpar("S_val",PS_val);
  157.     xml->addpar("R_val",PR_val);
  158.  
  159.     if ((Pfreemode!=0)||(!xml->minimal)){
  160.     for (int i=0;i<Penvpoints;i++){
  161.         xml->beginbranch("POINT",i);
  162.         if (i!=0) xml->addpar("dt",Penvdt[i]);
  163.         xml->addpar("val",Penvval[i]);
  164.         xml->endbranch();
  165.     };
  166.     };
  167. };
  168.  
  169.  
  170.  
  171. void EnvelopeParams::getfromXML(XMLwrapper *xml){
  172.     Pfreemode=xml->getparbool("free_mode",Pfreemode);    
  173.     Penvpoints=xml->getpar127("env_points",Penvpoints);
  174.     Penvsustain=xml->getpar127("env_sustain",Penvsustain);
  175.     Penvstretch=xml->getpar127("env_stretch",Penvstretch);
  176.     Pforcedrelease=xml->getparbool("forced_release",Pforcedrelease);
  177.     Plinearenvelope=xml->getparbool("linear_envelope",Plinearenvelope);
  178.  
  179.     PA_dt=xml->getpar127("A_dt",PA_dt);
  180.     PD_dt=xml->getpar127("D_dt",PD_dt);
  181.     PR_dt=xml->getpar127("R_dt",PR_dt);
  182.     PA_val=xml->getpar127("A_val",PA_val);
  183.     PD_val=xml->getpar127("D_val",PD_val);
  184.     PS_val=xml->getpar127("S_val",PS_val);
  185.     PR_val=xml->getpar127("R_val",PR_val);
  186.  
  187.     for (int i=0;i<Penvpoints;i++){
  188.         if (xml->enterbranch("POINT",i)==0) continue;
  189.         if (i!=0) Penvdt[i]=xml->getpar127("dt",Penvdt[i]);
  190.         Penvval[i]=xml->getpar127("val",Penvval[i]);
  191.     xml->exitbranch();
  192.     };
  193.     
  194.     if (!Pfreemode) converttofree();
  195. };
  196.  
  197.  
  198. void EnvelopeParams::defaults(){
  199.     Penvstretch=Denvstretch;
  200.     Pforcedrelease=Dforcedrelease;
  201.     Plinearenvelope=Dlinearenvelope;
  202.     PA_dt=DA_dt;
  203.     PD_dt=DD_dt;
  204.     PR_dt=DR_dt;
  205.     PA_val=DA_val;
  206.     PD_val=DD_val;
  207.     PS_val=DS_val;
  208.     PR_val=DR_val;
  209.     Pfreemode=0;
  210.     converttofree();
  211. };
  212.  
  213. void EnvelopeParams::store2defaults(){
  214.     Denvstretch=Penvstretch;
  215.     Dforcedrelease=Pforcedrelease;
  216.     Dlinearenvelope=Plinearenvelope;
  217.     DA_dt=PA_dt;
  218.     DD_dt=PD_dt;
  219.     DR_dt=PR_dt;
  220.     DA_val=PA_val;
  221.     DD_val=PD_val;
  222.     DS_val=PS_val;
  223.     DR_val=PR_val;
  224. };
  225.  
  226.  
  227.  
  228.